package by.kniazhych.core.server.local.logic.peaces {
	import by.kniazhych._old.core.data.PeaceType;
	import by.kniazhych.core.constants.UserColor;
	import by.kniazhych.core.data.game.PeacePosition;
	import by.kniazhych.core.server.local.logic.LogicController;
	import flash.geom.Point;
	/**
	 * ...
	 * @author Boutylin Mikhail
	 */
	public class AbstractPeace {
		
		protected var _type:uint;
		protected var _controller:LogicController
		
		public function AbstractPeace(controller:LogicController, type:uint) {
			_type = type;
			_controller = controller;
			if (!_controller) throw new ArgumentError("controller");
		}
		
		public function checkMotion(sP:PeacePosition, fP:PeacePosition):Boolean {
			return true;
		}
		
		public function isNobel():Boolean {
			return false;
		}
		
		protected function _checkCellClear(p:PeacePosition):Boolean {
			return _controller.data.getCellState(p) == 0;
		}
		
		protected function _isBlackPeaceCell(p:PeacePosition):Boolean {
			return PeaceType.BLACK_PEACES.indexOf(_controller.data.getCellState(p)) != -1;
		}
		
		protected function _isWhitePeaceCell(p:PeacePosition):Boolean {
			return PeaceType.WHITE_PEACES.indexOf(_controller.data.getCellState(p)) != -1;
		}
		
		protected function _isEnemyCell(p:PeacePosition):Boolean {
			return (_myColor == UserColor.WHITE ? _isBlackPeaceCell : _isWhitePeaceCell)(p); 
		}
		
		protected function _isMyCell(p:PeacePosition):Boolean {
			return (_myColor == UserColor.WHITE ? _isWhitePeaceCell : _isBlackPeaceCell)(p); 
		}
		
		protected function get _myColor():uint {
			if (PeaceType.WHITE_PEACES.indexOf(_type) != -1) return UserColor.WHITE;
			if (PeaceType.BLACK_PEACES.indexOf(_type) != -1) return UserColor.BLACK;
			throw new Error("unknown color");
		}
		
	}

}